package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-25 11:43
 **/
public class LeetCode537 {

    public String complexNumberMultiply(String num1, String num2) {
        //分割字符串(根据'+'或'i')
        String[] split1 = num1.split("\\+|i");
        String[] split2 = num2.split("\\+|i");
        int real1 = Integer.parseInt(split1[0]);
        int complex1 = Integer.parseInt(split1[1]);
        int real2 = Integer.parseInt(split2[0]);
        int complex2 = Integer.parseInt(split2[1]);
        return String.format("%d+%di", real1 * real2 - complex1 * complex2, complex1 * real2 + real1 * complex2);
    }

}
